package com.futao.serialize;

import com.futao.serialize.model.User;

import java.io.*;
import java.time.LocalDateTime;
import java.util.ArrayList;

/**
 * java序列化与反序列化
 *
 * @author ft
 * @date 2021/6/16
 */
public class Main {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        ArrayList<String> hobbyList = new ArrayList<>();
        hobbyList.add("抽烟");
        hobbyList.add("喝酒");
        hobbyList.add("烫头");
        User user = new User("一只特立独行的猪^(*￣(oo)￣)^", 28, hobbyList);
        user.setId(911);
        user.setCreateDateTime(LocalDateTime.now());
        user.setUpdateDateTime(LocalDateTime.now());

        ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream(new File("fff.txt")));
        objectOutputStream.writeObject(user);


        ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream(new File("fff.txt")));
        User readObject = (User) objectInputStream.readObject();
        System.out.println(readObject);
    }
}
